
#ifndef  HELPER_SCOPE_SCOPEGUARD_H
#define  HELPER_SCOPE_SCOPEGUARD_H

#include "IScopable.h"

namespace helper {
namespace scope {

template<typename T>
class ScopeGuard {
public:
    ScopeGuard(T & t, IScopable<T> & scopable)
    : t(t)
    , scopable(scopable)
    {
        scopable.enter(t);
    }
    ~ScopeGuard(){
        scopable.exit(t);
    }
private:
    T & t;
    IScopable<T> & scopable;
};


template<>
class ScopeGuard<void> {
public:
    ScopeGuard(IScopable<void> & scopable)
    :scopable(scopable)
    {
        scopable.enter();
    };
    ~ScopeGuard(){
        scopable.exit();
    }
private:
    IScopable<void> & scopable;
};

}// end of namespace scope
}// end of namespace helper

#endif   /* HELPER_SCOPE_SCOPEGUARD_H */
